package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.RoadLineFaultService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by pjn on 2017/8/5.
 */
@Controller
@RequestMapping("/rds_roadLineFault")
public class RoadLineFaultController {
    @Resource
    private RoadLineFaultService roadLineFaultService;

    @RequestMapping(value = "/getRoadLineReportFault4DT")
    @ResponseBody
    public DTResponseDto getRoadLineReportFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = roadLineFaultService.getRoadLineReportFault4DT(dtRequestDto, actorId, userId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/updateRoadLineFault")
    @ResponseBody
    public JsonMsgDto updateRoadLineFault(Integer roadLineFaultId, Integer roadLineFaultLevel, Integer roadLineFaultType, String roadLineFaultPhoto, String roadLineFaultReason, Double roadLineMoney) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineFaultService.updateRoadLineFault(roadLineFaultId, roadLineFaultLevel, roadLineFaultType, roadLineFaultPhoto, roadLineFaultReason, roadLineMoney));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteRoadLineFaultByIds")
    @ResponseBody
    public JsonMsgDto deleteRoadLineFaultByIds(String roadLineFaultIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineFaultService.deleteRoadLineFaultByIds(roadLineFaultIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }



    @RequestMapping(value = "/reportRoadLineFault")
    @ResponseBody
    public JsonMsgDto reportRoadLineFault(Integer roadLineId, Integer roadLineFaultCreatorId, Integer roadLineFaultLevel, Integer roadLineFaultType,
                                         String roadLineFaultPhoto, String roadLineFaultReason, Double roadLineMoney, Integer roadLineOrgId, Integer roadLineMainOrgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            roadLineFaultService.reportRoadLineFault(roadLineId, roadLineFaultCreatorId, roadLineFaultLevel, roadLineFaultType,
                    roadLineFaultPhoto, roadLineFaultReason, roadLineMoney, roadLineOrgId, roadLineMainOrgId);
            //为空是app端作判断
            jsonMsgDto.setJsonData("");
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadLineFaultIsReport")
    @ResponseBody
    public JsonMsgDto getRoadLineFaultIsReport(Integer roadLineId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadLineFaultService.getRoadLineFaultIsReport(roadLineId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getRoadLineFaultReport4DT")
    @ResponseBody
    public DTResponseDto getRoadLineFaultReport4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId,String roadName, String startRoad, String endRoad) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = roadLineFaultService.getRoadLineFaultReport4DT(dtRequestDto, actorId, orgId, roadName, startRoad, endRoad);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getStartRoad")
    @ResponseBody
    public JsonMsgDto getStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadLineFaultService.getStartRoad(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadLineFaultService.getSectionByStartRoad(roadName,actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadLineCoordinates4AppMap")
    @ResponseBody
    public JsonMsgDto getRoadLineCoordinates4AppMap(Integer orgId, Integer orgType, Integer actorId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineFaultService.getRoadLineCoordinates4AppMap(orgId, orgType, actorId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

}
